import { createRouter, createWebHashHistory } from 'vue-router'

const router = createRouter({
  history: createWebHashHistory(),
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition
    } else {
      return { top: 0 }
    }
  },
  routes: [
    {
      path: '/',
      component: () => import('@/views/Layout/index.vue'),
      children: [
        { path: '', component: () => import('@/views/Home/index.vue') },
        {
          path: '/category/:id',
          component: () => import('@/views/Category/index.vue'),
        },
        {
          path: '/goods/:id',
          component: () => import('@/views/Goods/index.vue'),
        },
      ],
    },
    { path: '/login', component: () => import('@/views/Login/index.vue') },
    {
      path: '/login/callback',
      component: () => import('@/views/Login/callback.vue'),
    },
    { path: '/text', component: () => import('@/views/Text/index.vue') },
  ],
})

export default router
